
import { PrismaClient } from '@prisma/client'
import { NextRequest, NextResponse } from 'next/server';
import OpenAI from 'openai';

const prisma = new PrismaClient()

export async function GET(request: NextRequest) {
  const searchParams = request.nextUrl.searchParams
  const id = searchParams.get('id')
  
  const moon = await prisma.moonCard.findUnique({
    where: { id: Number(id) }
  })

  const openai = new OpenAI({
    baseURL: 'https://aihubmix.com/v1',
    apiKey: 'sk-AQfahp4MDGQBdtWf52C7163798664b1c94F6578e64D6Ef09',
  });
  const completion: any = await openai.chat.completions.create({
    model: "DeepSeek-R1", // 替换模型 id
    messages: [
      {
         "role": "user",
         "content": `你是一个资深的月相神谕卡解读师，请帮我解读我抽到的卡片，我抽到的卡片是：${moon?.name}返回格式是纯文本`,
      }
    ]
  });

  return NextResponse.json({ message: '获取成功', data: {
    huida:completion.choices[0].message.content,
  }, code: 0 }, { status: 200 });
}